const API_URL = 'https://tea.qingnian8.com/api/bizhi'

export function request(method, url, data) {
  return new Promise((resolve, reject) => {
    uni.request({
      method: method.toLocaleUpperCase(),
      url: API_URL + url,
      data: data,
      header: {
        'access-key': 'hzh#20200808',
      },
      success: res => {
        const { errCode, errMsg, data } = res.data
        if (errCode !== 0) {
          uni.showModal({
            title: '系统提示',
            content: errMsg,
            showCancel: false,
          })
          reject(data)
          return
        }
        resolve(data)
      },
      fail: err => {
        reject(err)
      },
    })
  })
}
